<?php
//Main file
include('head.php');
include('menu.php');
?>
<div id="content">
<h2>Квадратное уравнение</h2>
<form action="" method="POST">
    <input name="a" size="3" value=""> x<sup>2</sup> + 
    <input name="b" size="3" value=""> x +  
    <input name="c" size="3" value=""> = 0 &nbsp;<input name="calculate" type="submit" value="Отправить"> 
</form>
<?php
  $result = '';
  $a = $b = $c = 0;
  
  if (isset($_POST['calculate'])) {
    $a = $_POST['a'];
    $b = $_POST['b'];
    $c = $_POST['c'];
    if($a != 0){
      $discriminant = $b * $b - 4 * $a * $c;
      if($discriminant > 0){
        $x1 = (-$b - sqrt($discriminant)) / (2 * $a);
        $x2 = (-$b + sqrt($discriminant)) / (2 * $a);
        echo "x<sub>1</sub> = " . $x1 . "<br />x<sub>2</sub> = " . $x2 . "<br />";
      } elseif ($discriminant == 0) {
        $x = -$b / ($a * 2);
        echo "x = " . $x . "<br /> Только один корень";
      } else {
        echo "Корней нет";
      }
    } elseif($b != 0) {
      $x = -$c / $b;
      echo "x = " . $x . "<br />";
    } else {
      echo "Ошибка";
    }
  }
?>
</div>
<?php
include('bottom.php');
?>